//
//  GLShaderHelper.m
//  LMPhotoVideoSDK
//
//  Created by Aimar on 16/7/19.
//  Copyright © 2016年 魁钺会. All rights reserved.
//

#import "GLShaderHelper.h"

static GLShaderHelper* sInstance = nil;

@interface GLShaderHelper ()

@property (nonatomic, strong)NSMutableDictionary*       presetShaders;

@end

@implementation GLShaderHelper

+ (instancetype)shareInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sInstance = [[GLShaderHelper alloc] init];
    });
    return sInstance;
}

- (id)init {
    self = [super init];
    if (self) {
        self.presetShaders = [[NSMutableDictionary alloc] initWithCapacity:10];
    }
    
    return self;
}

- (GLShader*)getPresetShader:(GLPresetShaderType)type {
    GLShader* shader = [self.presetShaders objectForKey:@(type)];
    if (shader == nil) {
        switch (type) {
            case GLPresetShaderType_Nomarl:
                
                break;
                
            case GLPresetShaderType_NormalTexture:
                shader = [[GLTextureShader alloc] initWithVertexString:normal_texture_vertex_shader fragmentString:normal_texture_fragment_shader];
                [self.presetShaders setObject:shader forKey:@(type)];
                break;
                
            default:
                break;
        }
    }

    return shader;
}

@end
